using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Haidou.Wpf.Util.Converters;

public class StringToStaticResource : IValueConverter
{
	public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
	{
		string? str = value as string;

		return string.IsNullOrWhiteSpace(str) || Application.Current == null || !Application.Current.Resources.Contains(str)
			? DependencyProperty.UnsetValue
			: Application.Current.Resources[str];
	}

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		return Binding.DoNothing;
	}
}